//
//  LSZNewTabbarAudioVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/3/2.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZNewTabbarAudioVC.h"
#import "LSZAudioCollectionReusableView.h"//区头的单元格
#import "UIViewController+LCMobShare.h"

#import "LSZNewTabbarAudioVC+LCCycle.h"
#import "NetworkTool+LCAVPlay.h"


@interface LSZNewTabbarAudioVC ()
<UITextFieldDelegate>

@property (assign,  nonatomic) bool isPop;
//@property (strong, nonatomic) LCTopTitleImageBar *topTitleImageBar;

@end
static NSString * const collectionCellIndentider = @"FootCell";
@implementation LSZNewTabbarAudioVC
#pragma mark  - 查看是否有缓存和请求的数据
-(void)determineIfThereIsCache :(NSString *)string
{
    __weak typeof(self) weakSelf = self;
    NSString * str = [NSString stringWithFormat:@"%@_tabbar",shouye_yinpin];
     [LSZCacheHandling initWithfindPlist:str :^(BOOL isOk, NSDictionary * dic) {
        if (isOk == YES) {
            LSZNewAudioHomepageManager * manager  = [[LSZNewAudioHomepageManager alloc]initWithNewAudioHomepage:dic];
             self.NewAudioHomepageManager = manager;
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [weakSelf.collectionView reloadData];
            }];
        }else{
         [self initWithStr:string];
        }
    }];
}
-(void)GetNewData
{
    [LSZRequestResolutionDic NewAudioClassification:^(BOOL isOK, NSString * str, LSZNewAudioHomepageManager * manager) {
        if (isOK == YES) {
            self.NewAudioHomepageManager = manager;
            [self.collectionView reloadData];
        }else{
            [self determineIfThereIsCache :str];
        }
    }];
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    AppDelegate *appdelegate = ((AppDelegate *)[[UIApplication sharedApplication] delegate]);
    appdelegate.rotateDirection = 0;
//    _topTitleImageBar.isPushSerach = YES;
    if (_isPop) {
        [self reloadTableView];//执行POP的方法，比如你POP回来后需要刷新表格。
    }else{
        //执行PUSH进来时的方法。
    }
    _isPop=YES;//将标志设置为YES。
}
//刷新当前的cell数据
-(void)reloadTableView{
    [self.collectionView reloadData];
    if (_LCPlayer.kstatus == LCMusicPlayerStatusPlaying) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LCPlayStatusStartAnimatingNotification" object:self userInfo:nil];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    _isPop=YES;//将标志设置为YES。
//    [self setupTitleImageView];
//    CGFloat width = (ScreenWidth - 40 -1) / 3;
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc]init];
//    flowLayout.itemSize = CGSizeMake(width, width + 40);
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.sectionInset = UIEdgeInsetsMake(0,10,0, 10);//分别为上、左、下、右
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-TAB_BAR_HEIGHT-NAVIGATION_BAR_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
     self.collectionView.backgroundColor = RGBColor(236, 236, 236);
    //添加以下代码关闭估算行高
    [self.view addSubview:self.collectionView];
    // 注册轮播器
    // 实现自定义 section 头视图 需要 子类化 UICollectionReusableView
    [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CycleScrollViewContainer"];
    [self.collectionView registerClass:[LSZAudioZuoErCollectionViewCell class] forCellWithReuseIdentifier:@"LSZAudioZuoErCollectionViewCell"];
    [self.collectionView registerClass:[LSZAudioCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionCellIndentider];
    [self.collectionView registerClass:[LSZAudioMusicCollectionViewCell class] forCellWithReuseIdentifier:@"LSZAudioMusicCollectionViewCell"];
    [self.collectionView registerClass:[LSZChangeCollectionViewCell class] forCellWithReuseIdentifier:@"LSZChangeCollectionViewCell"];
    [self.collectionView registerClass:[LSZCategoriesChoiceCVCell class] forCellWithReuseIdentifier:@"LSZCategoriesChoiceCVCell"];
    [self GetNewData];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self categoryNeedsToBeAddedNotice];
}
///创建Title图片
//- (void)setupTitleImageView {
//    LCTopTitleImageBar *topTitleImageBar = [[LCTopTitleImageBar alloc] init];
//    _topTitleImageBar = topTitleImageBar;
//    topTitleImageBar.searchTipLable.text = @"搜索音频、赞美诗...";
//    self.navigationItem.titleView = topTitleImageBar;
//    __weak typeof(self) weakSelf = self;
//    topTitleImageBar.serachBlock = ^{
//        [weakSelf clickPushSearchView];
//    };
//}
#pragma mark - 进入搜索界面
//- (void)clickPushSearchView{
//    _topTitleImageBar.isPushSerach = NO;
//    LSZAudioRViewController * vc = [[LSZAudioRViewController alloc]init];
//    [self.navigationController pushViewController:vc animated:YES];
//}
#pragma mark <UICollectionViewDataSource>
#pragma mark - 设置有几个区
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
     return self.NewAudioHomepageManager.arrayData.count + 1;
}
#pragma mark - 设置每个区有几个
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    // 定义的轮播器视图
    if(section == 0) {
        return 1;
    }else{
        LSZNewAudioHomepageMg * mg = nil;
        mg = self.NewAudioHomepageManager.arrayData[section-1];
        return mg.arrayList.count+mg.arrayDetail.count +1;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 0){
        LSZCategoriesChoiceCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZCategoriesChoiceCVCell" forIndexPath:indexPath];
        __weak typeof(self) weakSelf = self;
        [cell.imageViewOne tapGesture:^(UIGestureRecognizer *ges) {
            LSZPraisePoetryChartsViewController * VC = [[LSZPraisePoetryChartsViewController alloc]init];
            [weakSelf.navigationController pushViewController:VC animated:YES];
        }];
        [cell.imageViewTwo tapGesture:^(UIGestureRecognizer *ges) {
            [self initWithGoToNextPage:@"歌手/牧师" type:@"geshou"];
        }];
        [cell.imageViewThree tapGesture:^(UIGestureRecognizer *ges) {
            [self initWithGoToNextPage:@"专辑" type:@"zhuanji"];
        }];
        [cell.imageViewFour tapGesture:^(UIGestureRecognizer *ges) {
            [self initWithGoToNextPage:@"福音电台" type:@"diantai"];
        }];
        [cell.imageViewFive tapGesture:^(UIGestureRecognizer *ges) {
            if ([[_UserM usercode] isEqualToString:@""]) {
                pushAccLoginVC;
            }else{
                LSZAudioCollectionViewController * vc = [[LSZAudioCollectionViewController alloc]init];
                vc.uid = @"";
                [self.navigationController pushViewController:vc animated:YES];
            }
        }];
        [cell.imageViewSix tapGesture:^(UIGestureRecognizer *ges) {
            LSZDownloadVC *viewController = [[LSZDownloadVC alloc] init];
            viewController.title = @"已下载";
            [self.navigationController pushViewController:viewController animated:YES];
        }];
        [cell.imageViewSeven tapGesture:^(UIGestureRecognizer *ges) {
            LSZAudioSermonsVC * vc = [[LSZAudioSermonsVC alloc]init];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }];
        [cell.imageViewEight tapGesture:^(UIGestureRecognizer *ges) {
            LSZAddMVParentViewController * vc = [[LSZAddMVParentViewController alloc]init];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }];
        return cell;
    }else{
      return   [self collectionV:collectionView cellForIndexPath:indexPath];
    }
}
- (UICollectionViewCell *)collectionV:(UICollectionView *)collectionView cellForIndexPath:(NSIndexPath *)indexPath
{
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[indexPath.section-1];
    if (indexPath.row < mg.arrayList.count) {
        LSZAudioZuoErCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZAudioZuoErCollectionViewCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
        LSZNewAudioHomepageMg * audioMg = nil;
        audioMg = mg.arrayList[indexPath.row];
        [cell.imageViewIcon  sd_setImageWithURL:[NSURL URLWithString:audioMg.image] placeholderImage:[UIImage imageNamed:@"我的_设置_关于"]];
        cell.titleLabel.text = [NSString stringWithFormat:@"%@",audioMg.singerName];
        cell.titleLabel.textAlignment = NSTextAlignmentCenter;
        cell.labelClick.text = audioMg.hits;
        CGFloat width = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelClick sizeMaxWidth:cell.imageViewIcon.frame.size.width]+3;
        [cell.labelClick mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.offset(width);
        }];

        cell.labelTotal.text = [NSString stringWithFormat:@"共%@首",audioMg.total_song];
        cell.backgroundColor = RGBColor(236, 236, 236);
        return cell;
    }else{
        if (indexPath.row >=mg.arrayList.count+mg.arrayDetail.count) {
            LSZChangeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZChangeCollectionViewCell" forIndexPath:indexPath];
            cell.butFChange.tag = indexPath.section;
            [cell.butFChange addTarget:self action:@selector(clickChangeBut:) forControlEvents:UIControlEventTouchUpInside];
            return cell;
        }
        LSZAudioMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZAudioMusicCollectionViewCell" forIndexPath:indexPath];
        cell.lableTitle.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        LSZNewAudioHomepageMg * audioMg = nil;
        audioMg = mg.arrayDetail[indexPath.row-mg.arrayList.count];
        cell.labelNumber.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row-mg.arrayList.count+1];
        cell.lableTitle.text = NSStr(audioMg.title);
        cell.labelIntroduce.text = [NSString stringWithFormat:@"%@-%@",audioMg.singerName,audioMg.album];
        if ([audioMg.id_id isEqualToString:_LCPlayer.playingSong.id_id] &&
            [cell.lableTitle.text isEqualToString:_LCPlayer.playingSong.title]) {
            [cell didSelectRowCellWithIsSystemRed:YES];
        }else{
            [cell didSelectRowCellWithIsSystemRed:NO];
        }
        //耳机
        [LSZSpecialPackaging adaptiveWidth:cell.labelIntroduce str:cell.labelIntroduce.text sizeMaxWidth:ScreenWidth sizeMaxHeight:cell.labelIntroduce.frame.size.height];
        CGRect rect = cell.imageViewHeadset.frame;
        rect.origin.x = CGRectGetMaxX(cell.labelIntroduce.frame)+10;
        cell.imageViewHeadset.frame = rect;
        //次数
        cell.labelPlaysNumber.text = [NSString stringWithFormat:@"%@次",audioMg.click];

        CGRect rectPlays = cell.labelPlaysNumber.frame;
        rectPlays.origin.x = CGRectGetMaxX(cell.imageViewHeadset.frame)+2;
        rectPlays.size.width = [LSZSpecialPackaging getsTheAdaptiveWidth:cell.labelPlaysNumber sizeMaxWidth:ScreenWidth-CGRectGetMinX(cell.labelPlaysNumber.frame)-cell.butMove.frame.size.width]+28;
        cell.labelPlaysNumber.frame = rectPlays;

        if (CGRectGetMaxX(cell.labelPlaysNumber.frame)>CGRectGetMinX(cell.butMove.frame)) {
            cell.imageViewHeadset.hidden = YES;
            cell.labelPlaysNumber.hidden = YES;
        }else{
            cell.imageViewHeadset.hidden = NO;
            cell.labelPlaysNumber.hidden = NO;
        }
        cell.butMove.tag = [[NSString stringWithFormat:@"%zd%zd",(long)indexPath.section,(long)indexPath.row-mg.arrayList.count] integerValue];
        [cell.butMove addTarget:self action:@selector(clickButMoveTabbar:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
}
#pragma mark - 类别也就是更多按钮
-(void)clickButMoveTabbar:(UIButton *)but
{
    NSString * strTab = [NSString stringWithFormat:@"%zd",(long)but.tag];
    NSString * str1 = [strTab substringToIndex:1];//区
    NSString * str2 = [strTab substringFromIndex:1];//行
    self.clickCategoryNumberSection = [str1 integerValue]-1;
    self.clickCategoryNumberRow = [str2 intValue];
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[self.clickCategoryNumberSection];
    LSZNewAudioHomepageMg * audioMg = nil;
    audioMg = mg.arrayDetail[self.clickCategoryNumberRow];
    LSZPopoverViewController * vc = [[LSZPopoverViewController alloc]init];
    [vc show];
    [vc selectIndexRowWith:2];//布局
    [vc getMusicId:audioMg.id_id];
    [vc distinguishType:@"3"];
    [vc fromWhichInterface:@"LSZNewTabbarAudioVC"];
}
#pragma mark - 类别需要添加的通知
-(void)categoryNeedsToBeAddedNotice
{
    NSString * stringCollection = [NSString stringWithFormat:@"%@Collection",@"LSZNewTabbarAudioVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(LSZNewTabbarAudioVCCollection:) name:stringCollection object:nil];//收藏歌曲成功的通知
    NSString * stringNewTabbarAudio = [NSString stringWithFormat:@"%@newSongList",@"LSZNewTabbarAudioVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NewTabbarAudio) name:stringNewTabbarAudio object:nil];//点击新创文件夹

    NSString * strShare = [NSString stringWithFormat:@"%@",@"LSZNewTabbarAudioVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationLSZNewTabbarAudioVCShare) name:strShare object:nil];//点击分享歌曲的通知
    NSString * strDownload = [NSString stringWithFormat:@"%@Download",@"LSZNewTabbarAudioVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationLSZNewTabbarAudioVCDownload) name:strDownload object:nil];//点击下载的通知
    NSString * stringLogin = [NSString stringWithFormat:@"%@Login",@"LSZNewTabbarAudioVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationLSZNewTabbarAudioVCLogin) name:stringLogin object:nil];//点击收藏  用户没登录
}
#pragma mark - 收藏的提醒
-(void)LSZNewTabbarAudioVCCollection:(NSNotification *)notification
{
    NSDictionary * diction = notification.userInfo;
    if ([diction[@"ok"] isEqualToString:@"YES"]) {
        [self initWithStr:@"收藏成功!"];
    }else{
        [self initWithStr:diction[@"str"]];
    }
}
#pragma mark - 点击新建文件夹
-(void)NewTabbarAudio
{
    //提示框添加文本输入框
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"创建新文件夹"
                                                                   message:@""
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action) {
                                                         for(UITextField *text in alert.textFields){
                                                             //响应事件//得到文本信息
                                                             [self addNewFolder:text.text];
                                                         }
                                                     }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
                                                             //响应事件
                                                             NSLog(@"取消action = %@", alert.textFields);
                                                         }];
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"输入新建文件夹名字";
    }];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 添加新的文件夹名字
-(void)addNewFolder :(NSString *)string
{
    [LSZRequestData TheAdditionOfFavorites:@"3" name:string :^(BOOL isOK, NSString * string, NSDictionary * dic) {
        if (isOK == YES) {
            NSString * cat =  NullStringjudgment(NSStr(dic[@"data"][@"cat"]));
            LSZNewAudioHomepageMg * mg = nil;
            mg = self.NewAudioHomepageManager.arrayData[self.clickCategoryNumberSection];
            LSZNewAudioHomepageMg * audioMg = nil;
            audioMg = mg.arrayDetail[self.clickCategoryNumberRow];
            [LSZRequestData getSongCollection:cat :audioMg.id_id :^(BOOL isOk, NSString * string, NSDictionary * dic) {
                [self initWithStr:string];
            }];
        }else{
            [self initWithStr:string];
        }
    }];
}
#pragma mark - 分享
-(void)InfoNotificationLSZNewTabbarAudioVCShare
{
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[self.clickCategoryNumberSection];
    LSZNewAudioHomepageMg * audioMg = nil;
    audioMg = mg.arrayDetail[self.clickCategoryNumberRow];
    [self shareAudioWithImageArray:@[audioMg.image] url:audioMg.fileUrl musicWebURL:audioMg.shareUrl title:audioMg.title contentMessage:audioMg.singerName type:(SSDKContentTypeAudio)];
}
#pragma mark - 下载
-(void)InfoNotificationLSZNewTabbarAudioVCDownload
{
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[self.clickCategoryNumberSection];
    LSZNewAudioHomepageMg * audioMg = nil;
    audioMg = mg.arrayDetail[self.clickCategoryNumberRow];
    JKSongsMessStatus *songsMessStatus;
    NSDictionary *json = [audioMg yy_modelToJSONObject];
    songsMessStatus = [JKSongsMessStatus yy_modelWithJSON:json];
    [kNetworkTool downloadSongWithUrl:songsMessStatus];//下载歌曲文件
}
#pragma mark - 未登录
-(void)InfoNotificationLSZNewTabbarAudioVCLogin
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }
}
#pragma mark - 换一下 点击的那个
-(void)clickChangeBut:(UIButton *)but
{
    self.clickNumberSection = but.tag;
    [self changeData];
}
#pragma mark - 切换换一下数据
-(void)changeData
{
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[self.clickNumberSection-1];
    [LSZRequestResolutionDic tabbarAvideoLetIsDoThat:mg.type size:@"5" page:@"1" :^(BOOL isOk, NSString * str, LSZAudioChangeManager * mg) {
        if (isOk == YES) {
            LSZNewAudioHomepageMg * audioMg = nil;
            audioMg = self.NewAudioHomepageManager.arrayData[self.clickNumberSection-1];
            audioMg.arrayDetail = mg.arrayData;
            NSIndexPath * indexpath = [NSIndexPath indexPathForRow:audioMg.arrayList.count inSection:self.clickNumberSection];
            NSIndexPath * indexpath2 = [NSIndexPath indexPathForRow:audioMg.arrayList.count+1 inSection:self.clickNumberSection];
            NSIndexPath * indexpath3 = [NSIndexPath indexPathForRow:audioMg.arrayList.count+2 inSection:self.clickNumberSection];
            NSIndexPath * indexpath4 = [NSIndexPath indexPathForRow:audioMg.arrayList.count+3 inSection:self.clickNumberSection];
            NSIndexPath * indexpath5 = [NSIndexPath indexPathForRow:audioMg.arrayList.count+4 inSection:self.clickNumberSection];
            [UIView performWithoutAnimation:^{
                [self.collectionView reloadItemsAtIndexPaths:@[indexpath,indexpath2,indexpath3,indexpath4,indexpath5]];
            }];
        }
    }];
}
#pragma mark - 点击进入详情页
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return;
    }
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[indexPath.section-1];
    if (indexPath.row < mg.arrayList.count) {
        LSZNewAudioPlayImageAndTableViewVC * vc = [[LSZNewAudioPlayImageAndTableViewVC alloc]init];
        LSZNewAudioHomepageMg * audioMg = nil;
        audioMg = mg.arrayList[indexPath.row];
        [LCUtils albumArtistDetailsInterfaceJump:vc audioMg:audioMg typeComeWhere:@"1"];
        vc.lastPageNumberRow = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        vc.lastSection = [NSString stringWithFormat:@"%ld",(long)indexPath.section-1];
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        if (indexPath.row >= mg.arrayList.count + mg.arrayDetail.count) {
            return;
        }
         LSZNewAudioHomepageMg * audioMg = nil;
         audioMg = mg.arrayDetail[indexPath.row-mg.arrayList.count];
#pragma mark - 如果当前播放的就是点击的直接返回
        if ([_LCPlayer.playingSong.id isEqualToString:[NSString stringWithFormat:@"%@",audioMg.id_id]]) {
            return;
        }
        [LSZRequestData songClickOnTheDataUpdates:audioMg.id_id :^(BOOL isOk, NSString * str, NSDictionary * dic) {
            if (isOk == YES) {
                 //点击数更新OK
                 audioMg.originalClick = [NSString stringWithFormat:@"%d",[audioMg.originalClick intValue]+1];
                audioMg.click  = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges: audioMg.originalClick];
                [UIView performWithoutAnimation:^{
                    [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
                }];
            }
        }];
        //添加播放的数据
        NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
        for (NSInteger i = 0; i <mg.arrayDetail.count; i++) {
            NSDictionary *json = [mg.arrayDetail[i] yy_modelToJSONObject];
            [mutableArray addObject:json];
        }
         [LSZSpecialPackaging addPlaylistWithArrayData:mutableArray.copy];

        LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
        _LCPlayer.songs = playlistTest.allSongs;
        [_LCPlayer playAtIndex:indexPath.row - mg.arrayList.count isSelectPlay:YES];//播放歌曲
        _LCPlayer.playingSong.id = audioMg.id_id;
    }
    [collectionView reloadData];
}
#pragma mark - 区头
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if([kind isEqualToString:UICollectionElementKindSectionHeader] && indexPath.section == 0) {
        UICollectionReusableView *cycleScrollViewContainer = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"CycleScrollViewContainer" forIndexPath:indexPath];
        // 使用我的图片轮播器
        /// 图片轮播器
        CGFloat cycleHeight = 160;
        if (self.pagerView == nil) {
            UIImageView *bgimageView = [[UIImageView alloc] init];
            self.bgimageView = bgimageView;
            bgimageView.image = [UIImage imageNamed:@"devotion_bannerB"];
            [cycleScrollViewContainer insertSubview:bgimageView atIndex:0];
            _bgimageView.frame = CGRectMake(10, 10, ScreenWidth-20, cycleHeight);
            [_bgimageView.layer setMasksToBounds:YES];
            [_bgimageView.layer setCornerRadius:4];
            [self loadDataWithPage:NO];
//            UIView * oneView = [[UIView alloc]init];
//            oneView.frame = CGRectMake(0, 0, ScreenWidth, cycleHeight/2+10);
//            oneView.backgroundColor = RGBColor(228, 83, 77);
//            [cycleScrollViewContainer addSubview:oneView];
//
//            UIView * TwoView = [[UIView alloc]init];
//            TwoView.frame = CGRectMake(0, CGRectGetMaxY(oneView.frame), ScreenWidth, cycleHeight/2);
//            TwoView.backgroundColor = [UIColor whiteColor];
//            [cycleScrollViewContainer addSubview:TwoView];

            [cycleScrollViewContainer addSubview:[self setupCycleWithCycleHeight:cycleHeight]];
        }
        self.pagerView.tag = 10001;
        return cycleScrollViewContainer;
    }else{
        UICollectionReusableView *reuseableView = nil;
        // 如果是section的头
        LSZAudioCollectionReusableView * headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionCellIndentider forIndexPath:indexPath];

        LSZNewAudioHomepageMg * mg = nil;
        mg = self.NewAudioHomepageManager.arrayData[indexPath.section-1];
        headerView.labelClass.text = mg.name;
        if ([mg.name isEqualToString:@"推荐"]) {
            headerView.buttonMove.hidden = YES;
        }else{
            headerView.buttonMove.hidden = NO;
            headerView.buttonMove.tag = indexPath.section;
        }
        [headerView.buttonMove addTarget:self action:@selector(clickMoveBut:) forControlEvents:UIControlEventTouchUpInside];
        reuseableView = headerView;
        return reuseableView;
    }
}
#pragma mark - 点击更多的按钮 专辑1 歌手2 热门3
-(void)clickMoveBut:(UIButton *)but
{
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[but.tag-1];
    [self initWithGoToNextPage:mg.name type:mg.type];
}
-(void)initWithGoToNextPage:(NSString *)name type:(NSString *)type
{
    LSZMoveCheckVC * vc = [[LSZMoveCheckVC alloc]init];
    vc.chooseTitleValue =  name;
    vc.chooseType = type;
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)initWithStr :(NSString *)message
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;//枚举类型不同的效果
    hud.label.text= [NSString stringWithFormat:@"%@",message];
    [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];
}
-(void)hiddenMBAction
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        //        return CGSizeMake(ScreenWidth,0.001);
        return CGSizeMake(ScreenWidth-20,170);
    }else{
        return CGSizeMake(ScreenWidth,40);
    }
}
#pragma mark - cell大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    if (indexPath.section == 0) {
        if (ScreenWidth == 320) {
            //5
            return CGSizeMake(ScreenWidth, ScreenWidth/2+16+4);
        }else if(ScreenWidth == 375){
            // 6 7
            return CGSizeMake(ScreenWidth, ScreenWidth/2+8);
        }else {
            //plus
            return CGSizeMake(ScreenWidth, ScreenWidth/2);
        }
    }
    LSZNewAudioHomepageMg * mg = nil;
    mg = self.NewAudioHomepageManager.arrayData[indexPath.section-1];
    if (indexPath.row < mg.arrayList.count) {
        CGFloat width = (ScreenWidth - 40 -1) / 3;
        return CGSizeMake(width, width + 40);
    }
    else{
        if (indexPath.section == self.NewAudioHomepageManager.arrayData.count && indexPath.row == mg.arrayList.count+mg.arrayDetail.count) {
            return CGSizeMake(ScreenWidth-20,70);//最后一个换一下
        }
        if (ScreenWidth == 320) {
            //5
            return CGSizeMake(ScreenWidth-20, 45);
        }else if(ScreenWidth == 375){
            // 6 7
            return CGSizeMake(ScreenWidth-20, 50);
        }else {
            //plus
            return CGSizeMake(ScreenWidth-20, 58);
        }
    }
}
//-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
//    if (section==0) {
//        return UIEdgeInsetsMake(15, 15, 5, 15);
//    }else{
//        return UIEdgeInsetsMake(0, 0 , 0, 0);//分别为上、左、下、右
//    }
//}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 1;
}
//两个cell之间的间距（同一行的cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 1;
}
@end
